/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import dao.TeacherDAO;
import java.util.List;
import model.PersistenceType;
import model.ReturnDTO;
import model.Teacher;

/**
 *
 * @author Moraes
 */
public class TeacherService {

    public String sayTeacher(String pNmTeacher) {
        Teacher teacher = new Teacher();
        TeacherDAO teacherDAO = new TeacherDAO();
        teacher = teacherDAO.selectById(Integer.parseInt(pNmTeacher));
        return "Professor " + teacher.getNmTeacher() + ".";
    }

    public ReturnDTO PersistTeacher(Teacher pTeacher, PersistenceType pPersistenceType) {
        
        TeacherDAO teacherDAO = new TeacherDAO();
        ReturnDTO returnDTO = new ReturnDTO();

        if (pPersistenceType.equals(PersistenceType.INSERT)) {
            try {
                teacherDAO.Insert(pTeacher);
                returnDTO.result = true;
            } catch (Exception e) {
                returnDTO.result = false;
                returnDTO.errorMessage = e.getMessage();
            }
        }

        return returnDTO;
    }
    public List<Teacher> getAll (){
        TeacherDAO teacherDAO = new TeacherDAO();
        return teacherDAO.selectAll();
    }
}
